package com.aigao.golf.common.file.service

import org.csource.fastdfs.StorageClient1
import org.springframework.http.HttpHeaders
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
import org.springframework.http.ResponseEntity
import org.springframework.web.multipart.MultipartFile

object FileExt{
    val GROUP1 = "group1"
}
public fun StorageClient1.upF(file : MultipartFile?,groupName : String) : String? {
    if( file == null || file.size == 0L ) {
        return null
    }
    return upload_file1(groupName,file.bytes,file.ext(),null)
}


public fun StorageClient1.dwN(fileId : String?,fileName : String) : ResponseEntity<ByteArray>{
    val headers = HttpHeaders()
    headers.setContentDispositionFormData("attachment", String(fileName.toByteArray(Charsets.UTF_8), Charsets.ISO_8859_1))
    headers.contentType = MediaType.APPLICATION_OCTET_STREAM
    var content = download_file1(fileId)
    return ResponseEntity(content,headers,HttpStatus.CREATED)
}




